//
//  WBBaseViewController.swift
//  WB123
//
//  Created by xuyunde mac pro on 2017/6/30.
//  Copyright © 2017年 NSObjiect. All rights reserved.
//

import UIKit

class WBBaseViewController: UIViewController {

    
    // 判断是否登录
    let isLogin: Bool = WBOAuthViewModel.share.isLogin
    // 设置全局访问视图View
    var visitorView: WBVisitorView?
    
    override func loadView() {
        // 判断用户是否登录
        if !isLogin {
            setupVisitorView()
        }else{
            // 用户登录了
            view = tableView
        }
    }
    // 监听事件
    @objc private func loginClick(){
//        print("监听按钮点击弹出控制器gogogo")
        let oAuthVC = WBAuthViewController()
        let nav = WBNavigationController(rootViewController: oAuthVC)
        //模态出
        present(nav, animated: true, completion: nil)
    }


    override func viewDidLoad() {
        super.viewDidLoad()
       setupNav()
    }
    //设置访客视图
    private func setupVisitorView(){
        // 实例化
        visitorView = WBVisitorView()
        // 02 实例化闭包
        visitorView?.closure = {[weak self] in
            // 04执行闭包
            self?.loginClick()
        }
        view = visitorView
        setupNav()
    }
    // 设置导航
    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: nil, title: "注册", target: self, action: #selector(loginClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(imgName: nil, title: "登录", target: self, action: #selector(loginClick))
    }
    // 列表
    lazy var tableView: UITableView = {
        
        let view = UITableView()
        return view
    }()
}
